<?php

class UserWithdrawalRecordLog extends BaseModel
{
    public $res;
    public $expire;

    public function getSource()
    {
        return "f_user_withdrawal_record_log";
    }


    public function lists($params = [], $columns = '*')
    {
        $page = isset($params['page']) ? $params['page'] : 1;
        $size = 10;
        if ($page > 0) {
            $page = ($page - 1) * $size;
        }
        $condition = '1=1 ';

        if (isset($params['phone']) && !empty($params['phone'])) {
            $userDb = new User();
            $info   = $userDb->findFirstByPhone($params['phone']);
            if (!$info) {
                return [];
            }
            $condition .= " and user_id = $info->id ";
        }
        if (isset($params['start_time']) && !empty($params['start_time'])) {
            $condition .= " and created_at >= '{$params['start_time']}'";
        }
        if (isset($params['end_time']) && !empty($params['end_time'])) {
            $condition .= " and created_at <= '{$params['end_time']}'";
        }
        $result['total'] = $this::count($condition);
        $result['list']  = $this::find(
            array(
                $condition,
                "order"   => 'id desc',
                'columns' => $columns,
                'limit'   => $size,
                'offset'  => $page
            ))->toarray();
        return $result;
    }
}
